package com.taoz.rpc.core.model;

import com.taoz.rpc.core.config.ApplicationConfig;
import lombok.Data;

/**
 *  etcd目前计划存储格式为 /项目名/接口名/host:ip
 *  项目名默认为ApplicationConfig里面的name
*/
@Data
 public class ServiceMetaInfo {
    private String name;  // 服务接口名
    private String host = ApplicationConfig.getConfig().getServerHost();  // 服务主机ip
    private int port = ApplicationConfig.getConfig().getServerPort();  // 服务端口

    public String getServiceKey() {
        return String.format("/%s/%s/%s", ApplicationConfig.getConfig().getName(), name, host + ":" + port);
    }

    public String getServiceAddress() {
        return String.format("http://%s:%s", host, port);
    }

    public static ServiceMetaInfo getInstanceByName(String name) {
        ServiceMetaInfo info = new ServiceMetaInfo();
        info.setName(name);
        return info;
    }
}
